<?php
class MaterialAction extends LoginAction
{
    public function index ()
    {
        $MaterialModel = M('Material');
        $material = $MaterialModel->select();
        if ($material) {
            $this->assign('material', $material);
        }
        $this->display();
    }
    /**
     * 添加材质属性操作
     * @author Ice iceinto@mallog.com.cn
     */
    public function add ()
    {
        if (isPost()) {
            $this->createAdd('Material');
        }
        $this->display();
    }
    /**
     * 修改材质属性操作
     * @author Ice iceinto@mallog.com.cn
     */
    public function edit ()
    {
        $material = null;
        $id = (int) getGetOrPost('id');
        $MaterialModel = D('Material');
        if ($id) {
            $map = array('id' => $id);
            $material = $MaterialModel->getMaterial($map);
        }
        if (isPost() && isset($material)) {
            $this->createUpdate('Material');
            $material = $MaterialModel->getMaterial($map);
        }
        if ($material) {
            $this->assign('material', $material);
            $this->display();
        } else {
            $this->error('对应材质属性不存在！');
        }
    }
}
?>